home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-11 / dbfedit.zip / DBFEDIT.PRG < prev   
Text File  |  1993-01-04  |  6KB  |  194 lines

  1. *╔════════════════════════════════════════════════╗
  2. *║    DBFEDIT  add/change data in a .dbf file     ║
  3. *║      by Tim L. Shafer       January 1989       ║
  4. *╚════════════════════════════════════════════════╝
  5. mROW = ROW()
  6. scrn = SAVESCREEN(0,0,24,80)
  7. PARAMETERS fname
  8. IF PCOUNT() > 0
  9.    fname = fname + '.dbf'
  10.    use &fname
  11. ELSE
  12.    fname = ' '
  13.    accept 'Enter .dbf name to edit: ' to fname
  14.    fname = fname + '.dbf'
  15.    use &fname
  16. ENDIF
  17. *
  18. set confirm on    && a full field requires <CR> with this ON.
  19. readexit(.T.)     && allows up/down arrow keys to terminate a READ.
  20. request  = 0      && tells DBEDIT() what to do on each keystroke.
  21. appending   = .F. && appending flags.
  22. appended_it = .F.
  23. clear screen
  24. @ 0,15 TO 4,65
  25. @ 1,17 say 'Press <ESC> to quit.  Use arrows / <CR> to move.'
  26. @ 2,17 say '    ^Home - 1st Field   ^End - Last Field'
  27. @ 3,17 say '   ^PgUp - 1st Record   ^PgDn - Last Record'
  28. @ 5, 0, 24, 79 BOX  '╒═╕│┘─└│'    && tlc, tl, trc, rl, brc, bl, blc, ll
  29. *
  30. DECLARE mfields[FCOUNT()]  && create an array to hold the field names.
  31. AFIELDS(mfields)           && fill the array with the field names.
  32. dbedit( 6, 1, 23, 78, mfields, 'tsedit', .T., .T., .T., .T., .T., .T.)
  33. * .T. isn't needed, but helps when changing one to a correct parameter.
  34. use
  35. RESTSCREEN(0,0,24,80,scrn)
  36. @ mROW, 0 say ''
  37. set cursor on
  38. QUIT
  39. *
  40. FUNCTION  tsedit
  41. *
  42. PARAMETERS  mode, litField    && these are passed from DBEDIT().
  43. PRIVATE  thedata, request
  44. r = ROW()
  45. c = COL()
  46. *
  47. request = 1
  48. mField = mFields[litField]
  49. keystroke  = LASTKEY()        && always save this to use later.
  50. *
  51. DO CASE
  52.    CASE  mode = 0                         && all keystrokes processed.
  53.       @  5,32 SAY '═════════════'         && blank out tob/eof messages
  54.       IF .NOT. appending
  55.          @ 24,32 SAY '─────────────'
  56.       ENDIF
  57.       del_stat()
  58.       request = 1
  59.  
  60.    CASE  mode = 1                         && attempt to go above 1st record
  61.       IF appending
  62.          request = IF(appended_it, 2, 3)
  63.          appending  = .F.
  64.          appended_it = .F.
  65.       ELSE
  66.          IF .NOT. EOF()
  67.             @ 5,32 say '<Top of File>'
  68.          ELSE
  69.             KEYBOARD CHR(5)
  70.          ENDIF
  71.       ENDIF
  72.  
  73.    CASE  mode = 2                         && moved below last record
  74.       IF appending
  75.          IF keystroke = 24 .AND. .NOT. EOF()
  76.             @ 24,32 say '<Add to File>'
  77.             request = 3
  78.          ELSE
  79.             IF keystroke = 30
  80.                request = IF(appended_it, 2, 3)
  81.                appending = .F.
  82.                appended_it = .F.
  83.             ENDIF
  84.          ENDIF
  85.       ELSE
  86.          IF keystroke = 24
  87.             @ 24,32 say '<Add to File>'
  88.             appending = .T.
  89.             request = 3
  90.          ENDIF
  91.       ENDIF
  92.       del_stat()
  93.  
  94.    CASE  mode = 3                      && The file is empty; append.
  95.       @ 5,32 say '<File Empty>'
  96.       appending = .T.
  97.       request = 3
  98.  
  99.    CASE  mode = 4                      && keystroke exception. Act on it.
  100.     DO CASE
  101.  
  102.       CASE keystroke = 27              &&  <ESC> = quit.
  103.          request = 0
  104.  
  105.  
  106.       CASE keystroke = 7               && delete key
  107.  
  108.          if DELETED()
  109.             recall
  110.          else
  111.             delete
  112.          endif
  113.          del_stat()
  114.  
  115.       CASE (keystroke > 31 .AND. keystroke < 127); && ASCII keys allowed as data
  116.             .AND. (appending .OR. (.NOT. EOF() .AND. LASTREC() <> 0))
  117.  
  118.          KEYBOARD CHR(keystroke)       && the keystroke must be forced back in.
  119.          set cursor on
  120.          thedata = &mFIELD
  121.          @ R, C GET thedata
  122.          READ
  123.          keystroke = LASTKEY()         && act on the last key read.
  124.  
  125.          IF keystroke <> 27 .AND. updated()  && <ESC> quits & leaves field intact.
  126.  
  127.             IF appending   .AND. EOF()
  128.                APPEND BLANK
  129.                appended_it = .T.
  130.             ENDIF
  131.  
  132.             REPLACE &mField WITH thedata
  133.  
  134.          ENDIF
  135.  
  136.          set cursor off
  137.  
  138.          IF request <> 2
  139.  
  140.             DO CASE
  141.                CASE  keystroke = 5 .OR. keystroke = 18   &&  up arrow/PgUp
  142.                   IF appending
  143.                      request = IF(appended_it, 2, 3)
  144.                      appending = .F.
  145.                      appended_it = .F.
  146.                   ELSE
  147.                      KEYBOARD CHR(5)                     && up arrow
  148.                   ENDIF
  149.                CASE  keystroke = 24                      && down arrow
  150.                   KEYBOARD CHR(24)
  151.                CASE  keystroke = 3 .AND. .NOT. appending &&  pg down
  152.                   KEYBOARD CHR(24)
  153.                CASE  keystroke = 13 .AND.;
  154.                        litField < FCOUNT()               &&  <CR>; move right
  155.                   KEYBOARD CHR(4)
  156.                CASE keystroke = 13 .AND.;
  157.                        litField = FCOUNT() &&  <CR> move down & to 1st field
  158.                   KEYBOARD CHR(29) + CHR(24)
  159.  
  160.             ENDCASE
  161.  
  162.          ENDIF
  163.  
  164.       CASE keystroke = 13 .AND. litField < FCOUNT()      && <CR>; move right
  165.          KEYBOARD CHR(4)
  166.  
  167.       CASE keystroke = 13 .AND. litField = FCOUNT()      && <CR>; last field
  168.          KEYBOARD CHR(29) + CHR(24)             && go to 1st field, next line
  169.          IF .NOT. appending .AND. EOF()
  170.             request = 3
  171.             appending = .T.
  172.          ENDIF
  173.  
  174.       ENDCASE
  175.  
  176. ENDCASE
  177. *
  178. RETURN request
  179. *
  180. *┌───────────────────────────────────────────┐
  181. *│ Show if the record is marked for deletion │
  182. *└───────────────────────────────────────────┘
  183. FUNCTION del_stat
  184. *
  185.    IF DELETED()
  186.       set color to *w+/n
  187.       @ 5, 60 SAY '<**  DELETED  **>'
  188.       set color to
  189.    ELSE
  190.       @ 5, 60 SAY '═════════════════'
  191.    ENDIF
  192.  RETURN .T.
  193. *
  194.